<%@page language="java" contentType="text/html;charset=UTF-8" import="java.sql.*" import="java.lang.Object" import="java.util.Date" import="java.security.MessageDigest"%>
<%@ page import="java.io.*"%>
<%@page import="Annotation.DataBase.*"%>
<%@page import="java.sql.*"%>
<%@ page import="java.util.HashMap"%>
<%@ page import="java.util.ArrayList"%>
<%
String ClusterNumber = request.getParameter("cn");
%>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>Update the quest result</title>
		<style type="text/css">
			th {text-align:center; vertical-align:top;}
			.source{width:250px; height:400px; padding:10px; border:1px solid #aaaaaa; background:cyan; box-shadow: 10px 10px 5px #dddddd;}
			.divbox{width:250px; height:70px; padding:10px; border:1px solid #aaaaaa; box-shadow: 10px 10px 5px #888888;}
			.items{width:200px; border:2px solid #a1a1a1; padding:5px 5px; background:#dddddd;}
		</style>

		
	</head>
	<body>
		<hr>
		
<%
String students[] ;
String clusters[];
int stuNum=0;
MySQLCommand ss= new MySQLCommand();

//這是正確的語法了
//String sqls="SELECT cluster_student_list FROM cluster_info WHERE PK_reading_activity = "+readingActiveID+";";
String sqls="SELECT cluster_student_list FROM cluster_info WHERE PK_reading_activity = 10 AND PK_cluster_approach = 3;";
out.println("輸入的語法:"+sqls+"<br>");
//ss.executeSQL(sqls);

ResultSet rss = ss.selectSQL(sqls);

out.println(sqls);

if(rss.next()==true){
	//has next(), has data already
	out.println("有資料");	
	String clusterList = rss.getString("cluster_student_list");
	out.println("取得的資料:"+clusterList+"<br>");
	
	//item10-div0###item12-div0###item11-div2###item9-div2###
	String m[]=clusterList.split("###");
	students=new String [m.length];
	clusters=new String [m.length];
	for(int i = 0; i < m.length ; i++)
	{
		String ItemDiv[] = m[i].split("-");
		students[i]=ItemDiv[0];
		clusters[i]=ItemDiv[1];
	}
	
%>
		Edit by Teacher
		<table width="600" border="1">			
			<tr>
				<th width="50%" style="padding:5px;">
					<%	
					for(int i=0;i<m.length;i++){
						if(!clusters[i].equals("")){
							out.print("<div id='"+clusters[i]+"' class='divbox' ondrop='drop(event)' ondragover='allowDrop(event)'>");
							out.print(clusters[i]);
							out.print("<div id='"+students[i]+"' class='items' ondragstart='drag(event)' draggable='true'>");
							out.print(students[i]);
							out.print("</div>");
							for(int j=i+1;j<m.length;j++){
								if(clusters[i].equals(clusters[j])){
									
									out.print("<div id='"+students[j]+"' class='items' ondragstart='drag(event)' draggable='true'>");
									out.print(students[j]);
									out.print("</div>");
									//out.print("</div><p>");
									
									//out.println("i和j相同<br>");
									clusters[j]="";
									
									
								}
								
							}	
							out.print("</div><p>");
						}
						clusters[i]="";
						//out.println("比完i了:"+i+"<br>");
						//out.println(students[i]);
						//out.println(debug+"");
					}
					
					%>

				</th>
			</tr>				
		</table>		
		
		
<%
}
ss.closeDB();
//↓對的語法
//UPDATE cluster_info SET cluster_student_list = 'item10-div0###item12-div0###item11-div2###item9-div2###' WHERE PK_reading_activity = 2 AND PK_cluster_approach = 2; 
%>		
		
		
		<table width="600" border="1">			
			<tr>
				
				<th width="50%" style="padding:5px;">
	    			<input type="button" id="saveResult" name="saveResult" onClick="" value="Save Result"/>
	    			<input type="button" id="createCluster" name="create" onClick="numberAdding(event)" value="Edit clusters"/>
				</th>
			</tr>		
						
		</table>	
			
				
	</body>
</html>